/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleshipgame.logic;
import battleshipgame.logic.Board;
/**
 *
 * @author אלירן
 */
public class Coordinate {
    int X;
        int Y;
        public int getX() {
            return X;
        }
        public void setX(int x) {
            this.X = x;
        }
        public int getY() {
            return Y;
        }
        public void setY(int y) {
            this.Y = y;
        }
        public Coordinate(int x, int y) {
            this.X = x;
            this.Y = y;
        }
        /*
         * TODO add throws invalid InvalidInputException
         */
        public static Coordinate ConvertStringToXY(String str) throws InvalidInputException{
            char a,b; //coordinates
            int x,y ;
            Coordinate res;
            a = str.charAt(0);
            x =  a - 'A' ;
            try
            {
            y = Integer.parseInt(str.substring(1));
            }
            catch(NumberFormatException e)
            {
                throw new InvalidInputException("Not valid location is board. (Coordinate) " + str);
            }
            y--;
            res = new Coordinate (x, y);
            if ( !res.IsValidLocationInBoard())
                throw new InvalidInputException("Not valid location is board. (Coordinate) " + str);
            return  res ;
        }  
        static boolean  IsValidLocationInBoard(Coordinate coordinate) {
            if ( coordinate.IsValidLocationInBoard())
                return true;
            return false; 
        }
        public boolean IsValidLocationInBoard() {
            if ( X >= 0  && X < Constants.BOARD_SIZE && Y >= 0  && Y < Constants.BOARD_SIZE )
                return true;       
            return false; 
        }
}
